import Vue from 'vue'
import Router from 'vue-router'
import login from '@/view/login/login'
import mainBox from '@/view/main'

import homePage from '@/view/homepage/homepage'
import shopHome from '@/view/homePage/shopHome'
import shopAdministration from '@/view/homePage/shopAdministration'
import edit from '@/view/homepage/edit'
import runningDetail from '@/view/homePage/runningDetail'
import addCoupon from '@/view/homePage/addCoupon'

import goodsCenter from '@/view/goodsCenter/goodsCenter'
import goodsList from '@/view/goodsCenter/goodsList'
import goodsRelease from '@/view/goodsCenter/goodsRelease'
import goodsEvaluate from '@/view/goodsCenter/goodsEvaluate'
import evaluateDetail from '@/view/goodsCenter/evaluateDetail'

import goodsClassify from '@/view/goodsCenter/goodsClassify'
import tagLibrary from '@/view/goodsCenter/tagLibrary'

import orders from '@/view/orderCenter/orders'
import orderList from '@/view/orderCenter/orderList'
import orderDetail from '@/view/orderCenter/orderDetail'

Vue.use(Router)

const routes = [
  {
    path: '/login',
    name: login,
    component: login
  },
  {
    path: '/',
    component: mainBox,
    name: 'mainBox',
    redirect: { name: 'homePage' },
    meta: { title: '主入口整体布局' },
    children: [
      {
        path: 'homePage',
        component: homePage,
        name: 'homePage',
        redirect: { name: 'shopHome' },
        meta: { title: '管理首页' },
        id: '01',
        children: [
          {
            path: 'shopHome',
            component: shopHome,
            name: 'shopHome',
            nameIcon: '&#xe630;',
            showType: 1,
            id: '011',
            meta: { title: '店铺主页' },
            children: [
              {
                path: 'edit',
                component: edit,
                name: 'edit',
                showType: 2,
                id: '013',
                meta: { title: '资料编辑' }
              }, {
                path: 'runningDetail',
                component: runningDetail,
                name: 'runningDetail',
                showType: 2,
                id: '014',
                meta: { title: '流水明细' }
              }
            ]
          }, {
            path: 'shopAdministration',
            component: shopAdministration,
            name: 'shopAdministration',
            nameIcon: '&#xe606;',
            showType: 1,
            id: '012',
            meta: { title: '店铺管理' },
            children: [
              {
                path: 'addCoupon',
                component: addCoupon,
                name: 'addCoupon',
                showType: 2,
                meta: { title: '添加优惠券' }
              }
            ]
          }
        ]
      },
      {
        path: 'goodsCenter',
        component: goodsCenter,
        name: 'goodsCenter',
        redirect: { name: 'goodsList' },
        meta: { title: '商品中心' },
        id: '02',
        children: [
          {
            path: 'goodsList',
            component: goodsList,
            name: 'goodsList',
            nameIcon: '&#xe612;',
            showType: 1,
            id: '015',
            meta: { title: '商品列表' }
          },
          {
            path: 'goodsRelease',
            component: goodsRelease,
            nameIcon: '&#xe656;',
            name: 'goodsRelease',
            showType: 1,
            id: '016',
            meta: { title: '商品发布' }
          },
          {
            path: 'goodsEvaluate',
            component: goodsEvaluate,
            nameIcon: '&#xe639;',
            showType: 1,
            id: '017',
            name: 'goodsEvaluate',
            meta: { title: '商品评价' },
            children: [
              {
                path: 'evaluateDetail',
                name: 'evaluateDetail',
                component: evaluateDetail,
                meta: { title: '查看订单' },
                showType: 2
              }
            ]
          },
          {
            path: 'goodsClassify',
            component: goodsClassify,
            name: 'goodsClassify',
            nameIcon: '&#xe620;',
            showType: 1,
            id: '018',
            meta: { title: '商品分类' }
          },
          {
            path: 'tagLibrary',
            component: tagLibrary,
            name: 'tagLibrary',
            nameIcon: '&#xe70f;',
            showType: 1,
            id: '019',
            meta: { title: '标签库' }
          }
        ]
      },
      {
        path: 'orders',
        component: orders,
        name: 'orders',
        redirect: { name: 'orderList' },
        meta: { title: '订单中心' },
        id: '03',
        children: [
          {
            path: 'orderList',
            component: orderList,
            name: 'orderList',
            nameIcon: '&#xe70f;',
            showType: 1,
            id: '020',
            meta: { title: '订单列表' },
            children: [
              {
                path: 'orderDetail',
                component: orderDetail,
                name: 'orderDetail',
                showType: 2,
                meta: { title: '订单详情' }
              }
            ]
          }
        ]
      }
    ],
    beforeEnter (to, from, next) {
      let token = Vue.cookie.get('token')
      console.log(`token:${token}`)
      if (!token || !/\S/.test(token)) {
        next({ path: '/login' })
      }
      next()
    }
  }
]
const router = new Router({
  linkActiveClass: 'nav-active',
  // mode: 'history',
  routes
})

export default router
